#include <bits/stdc++.h>

#define in read()
#define fi first
#define se second
#define pb push_back
#define rep(i, x, y) for(int i = (x); i <= (y); i++) 
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

using ll = long long;
using db = double;
using pii = pair < int , int >;
using vec = vector < int >;
using veg = vector < pii >;

int read() {
	int x = 0; bool f = 0; char ch = getchar(); while(!isdigit(ch)) f |= ch == '-', ch = getchar(); 
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar(); return f ? -x : x;
}

const int N = 210;
const int S = 1 << 17;
const int inf = 0x3f3f3f3f;

int f[N][S][2], n, a[N], K;

void upd(int &x, int y) { x = min(x, y); }

int main() {
#ifndef ONLINE_JUDGE
	freopen("1.in", "r", stdin);
#endif
	n = in; K = in; rep(i, 1, n) a[i] = in;
	memset(f, 0x3f, sizeof f);
	f[0][0][0] = 0; int U = 1 << K; U--;
	rep(i, 1, n) {
		rep(s, 0, U) {
			rep(d, 0, 1) {
				if(f[i - 1][s][d] < inf) {
					if(!(s >> a[i] - 1 & 1)) {
						int suf = 0;
						rep(kk, a[i], K - 1) if(s >> kk & 1) suf++;
						upd(f[i][s | 1 << a[i] - 1][d], f[i - 1][s][d] + suf);
					}
					
					upd(f[i][s][1], f[i - 1][s][d] + K - __builtin_popcount(s));
					if(d == 0) {
						upd(f[i][s][0], f[i - 1][s][0] + __builtin_popcount(s));
					}
				}
			}
		}
	}
	int ans = inf;
	rep(d, 0, 1) upd(ans, f[n][U][d]);
	cout << ans << endl;
	return 0;
}
